using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.ValidatorNodes;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using EntLibContrib.Validation.Design.UI;

namespace EntLibContrib.Validation.Design
{
    public class TestValidatorCommand : ValidateNodeCommand
    {
        public TestValidatorCommand(IServiceProvider serviceProvider)
            :base(serviceProvider)
        {
        }

        protected override void ExecuteCore(ConfigurationNode node)
        {
            base.ExecuteCore(node);
            if (this.ValidationSucceeded)
            {
                SingleValidatorNodeBase validator = node as SingleValidatorNodeBase;
                if (validator != null)
                {
                    ValidatorData validatorData = validator.CreateValidatorData();
                    using (TestValidatorUI validatorTestUI = new TestValidatorUI(validatorData))
                    {
                        validatorTestUI.ShowDialog();
                    }
                }
            }
        }
    }
}
